package kr.hyunist.androidcomplete01saeildamil.ch13;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.DatePicker.OnDateChangedListener;

public class DatePickerTest extends Activity {
	DatePicker mDate;
	TextView mTxtDate;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.datepickertest);
		
		mDate = (DatePicker) findViewById(R.id.datePickertestdp);
		mTxtDate = (TextView) findViewById(R.id.datePickertesttv);
		mDate.init(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(), new OnDateChangedListener() {
			
			@Override
			public void onDateChanged(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				mTxtDate.setText(String.format("%d/%d/%d", year, monthOfYear + 1, dayOfMonth));
			}
			
		});
		
		findViewById(R.id.datePickertestbtn).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String result = String.format("%d년 %d월 %d일", mDate.getYear(), mDate.getMonth() + 1, mDate.getDayOfMonth());
				Toast.makeText(DatePickerTest.this, result, Toast.LENGTH_SHORT).show();
			}
			
		});
	}
}
